package exe3;

//公司类
public class Company {
    String companyName;//公司名称
    String address;//注册地址
    String iphone;//电话
    String business;//经营范围
    int pos = 0;
    //员工数组
    Staff s[] = new Staff[10];

    //构造函数
    public Company() {

    }

    public Company(String companyName, String address, String iphone, String business, int pos) {
        this.companyName = companyName;
        this.address = address;
        this.iphone = iphone;
        this.business = business;
        this.pos = pos;
    }

    //招聘员工方法
    public boolean add(Staff staff) {
        if (pos >= s.length) {
            System.out.println("员工已满");
            return false;
        }
        for (int i = 0; i < pos; i++) {
            if (s[i].name.equals(staff.name)) {
                System.out.println("名字以重复");
                return false;
            }
        }
        s[pos++] = staff;
        return false;
    }

    public boolean add(int id, String name, String sex, String post, double money, String number, int years) {
        if (pos >= s.length) {
            System.out.println("员工已满");
            return false;
        }
//        for (int i = 0; i < pos; i++) {
//            if (s[i].name.equals(staff.name)) {
//                System.out.println("名字以重复");
//                return false;
//            }
//        }
        s[pos++] = new Staff(id,name,sex,post,money,number,years);
        return false;
    }

    //输出员工信息的方法
    public void show() {
        System.out.println("公司信息如下:");
        System.out.println("公司名称是:" + companyName);
        System.out.println("注册地址是:" + address);
        System.out.println("电话为:" + iphone + ",经营范围:" + business);
        System.out.println("员工信息如下:");
        for (int i = 0; i < pos; i++) {
            //s[i].show();
            System.out.println("员工的编号为:" + s[i].id + "员工姓名为:" + s[i].name + "员工的性别为:" + s[i].sex + "员工的职位为:" + s[i].post
                    + "员工的薪水为:" + s[i].money + "元,员工的身份证号:" + s[i].number + "员工工作年限为" + s[i].years + "年。");
            System.out.println();
        }
    }

    //辞退员工
    public void fire(String name) {
        for (int i = 0; i < s.length; i++) {
            if (s[i].name.equals(name)) {
                for (int j = i; j < s.length - 1; j++) {
                    s[j] = s[j + 1];
                }
                System.out.println("删除成功!");
                s[--pos] = null;//!!!!!
                return;
            } else {
                System.out.println("删除失败!");
                return;
            }
        }
    }

    //给全体员工涨薪,规则是根据工作年限，每一年涨50元。
    public void addSalary() {
        for (int i = 0; i < pos; i++) {
            s[i].money += s[i].years * 50;
        }
    }

    //查找薪水最高的员工，返回员工信息
    public Staff findTopSal() {
        if (pos < 1)
            return null;
        Staff temp = s[0];
        for (int i = 1; i < pos; i++) {
            if ((s[i].money > temp.money)) {
                temp = s[i];
            }
        }
        return temp;
    }
}